package com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hyphenate.chat.EMClient;
import com.hyphenate.easeui.utils.Preferences;
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.v3.MessageDialog;
import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.ninetaildemonfox.utils.AppManager;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.utils.GlideCacheUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/24 13:23
 * 功能描述：设置界面
 * 联系方式：1037438704@qq.com
 */
public class SetUpActivity extends BaseActivity {
    @BindView(R.id.image_left_finish)
    ImageView imageleftFinish;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.text_right)
    TextView textRight;
    @BindView(R.id.text_sign_out)
    TextView textSignOut;
    @BindView(R.id.text_change_password)
    TextView textChangePassword;
    @BindView(R.id.text_about_us)
    TextView textAboutUs;
    @BindView(R.id.ll_bingding)
    LinearLayout llBingding;
    @BindView(R.id.ll_cache)
    LinearLayout llCache;
    @BindView(R.id.text_feedback)
    TextView textFeedback;
    @BindView(R.id.text_privacy_settings)
    TextView textPrivacySettings;
    @BindView(R.id.text_binding_phone)
    TextView textBindingPhone;
    @BindView(R.id.text_getCacheSize)
    TextView textGetCacheSize;
    private GlideCacheUtil instance;
    private AppCompatActivity thisMe;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_set_up;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        thisMe = this;
        GlideCacheUtil instance = GlideCacheUtil.getInstance();
        textCenter.setText("设置");
        imageleftFinish.setVisibility(View.VISIBLE);
        String phone = Preferences.getInstance().getString(this, "name", "phone");
        phone = phone.substring(0, 3) + "****" + phone.substring(7, phone.length());
        textBindingPhone.setText(phone);
        //获取缓存
        textGetCacheSize.setText(instance.getCacheSize(thisMe));
//        getCacheSize

    }

    @OnClick({R.id.image_left_finish, R.id.text_sign_out, R.id.text_change_password, R.id.ll_bingding
            , R.id.ll_cache, R.id.text_feedback, R.id.text_privacy_settings, R.id.text_about_us})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left_finish:
                finish();
                break;
            case R.id.text_sign_out:
                //立即开通
                MessageDialog.show(thisMe, "是否确认退出？", "", "确认", "取消")
                        .setOnOkButtonClickListener(new OnDialogButtonClickListener() {
                            @Override
                            public boolean onClick(BaseDialog baseDialog, View v) {
                                EMClient.getInstance().logout(true);
                                Preferences.getInstance().cleanAll(thisMe, "user");
                                AppManager.getInstance().killActivity(MainActivity.class);
                                startActivity(new Intent(thisMe, LoginActivity.class));
                                finish();
                                return false;
                            }
                        });
                break;
            case R.id.text_change_password:
                //5 修改密码
                AuthenticateLoginActivity.start(this, 5);
                break;
            case R.id.ll_bingding:
                //6修改实际号验证
                AuthenticateLoginActivity.start(this, 6);
                break;
            case R.id.text_about_us:
                //关于我们
                startActivity(new Intent(this, AboutUsActivity.class));
                break;
            case R.id.ll_cache:
                //缓存
//                DialogShow.start(this, "4");
                //立即开通
                MessageDialog.show(thisMe, "确定要清除缓存吗？", "", "是", "否")
                        .setOnOkButtonClickListener(new OnDialogButtonClickListener() {
                            @Override
                            public boolean onClick(BaseDialog baseDialog, View v) {
                                instance = GlideCacheUtil.getInstance();
                                instance.clearImageAllCache(thisMe);
                                ShowToast(thisMe, "清除成功");
                                textGetCacheSize.setText(instance.getCacheSize(me));
                                return false;
                            }
                        });

                break;
            case R.id.text_feedback:
                //意见反馈
                FeedBackActivity.start(thisMe,FeedBackActivity.class,"2");
                break;
            case R.id.text_privacy_settings:
                //隐私设置
                startActivity(new Intent(this, PrivacySettingActivity.class));
                break;
            default:
        }
    }

}
